package tas.co.in.daoimpl.ExtensionInfo;

import java.util.List;
import java.util.StringTokenizer;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import tas.co.in.dao.ExtensionInfo.ExtensionInfo;
import tas.co.in.domain.ExtensionInfo.ExtensionInfoBean;

public class ExtensionInfoImpl extends SqlMapClientDaoSupport implements ExtensionInfo 
{
	public List<ExtensionInfoBean> getBufferExtenions() 
	{	
		try 
		{	
			ExtensionInfoBean bean=new ExtensionInfoBean();	
			bean.setGrouCode("CITYCODE");		
			return getSqlMapClient().queryForList("extensionInfo.ext", bean);
		}
		catch (Exception e) 
		{
			System.out.println(e);
		}
		return null;
	}
	
	public List<ExtensionInfoBean> getBufferCode(ExtensionInfoBean bean) 
	{	
		try 
		{
			bean.setGrouCode("EXTNCODE");		
			return getSqlMapClient().queryForList("extensionInfo.ext1", bean);
		}
		catch (Exception e) 
		{
			System.out.println(e);
		}
		return null;
	}

	public boolean setExtIP(ExtensionInfoBean bean) 
	{
		
		boolean flag = false;
		
		try 
		{
			getSqlMapClient().insert("extensionInfo.setExtension", bean);
			getSqlMapClient().insert("extensionInfo.setExtIP", bean);
			flag = true;
		} 
		catch (Exception e) 
		{
			System.out.println(e);
		}
		return flag;
	}
	
	public List<ExtensionInfoBean> getExtIP(ExtensionInfoBean bean)
	{	
		try 
		{
			return getSqlMapClient().queryForList("extensionInfo.getExtension", bean);
		}
		catch (Exception e) 
		{
			System.out.println(e);
		}
		return null;
	}
	
	public boolean delExtension(StringTokenizer items)
	{
		ExtensionInfoBean bean = new ExtensionInfoBean();
		boolean flag = false;
		try 
		{
			while(items.hasMoreTokens())
			{
				bean.setExtNumber(items.nextToken());
				bean.setIP(items.nextToken());
			}
			getSqlMapClient().delete("extensionInfo.deleteExtension", bean);
			getSqlMapClient().delete("extensionInfo.delExtIP", bean);
			flag = true;
		}
		catch (Exception e) 
		{
			System.out.println(e);
		}
		return flag;
	}
}